package com.sskj.finance.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.finance.bean.HomeBorrowBorrowInfoBean;
import com.sskj.finance.bean.HomeBorrowMortgageInfoBean;
import com.sskj.finance.bean.HomeQbwCoinsList;
import com.sskj.finance.http.HttpConfig;
import com.sskj.finance.ui.activity.BorrowActivity;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;


public class BorrowActivityPresenter extends BasePresenter<BorrowActivity> {

    /**
     * 获取借入币信息
     *
     * @param type     1押币借钱 2押钱借币
     * @param out_code 抵押币种标识，如：BTC ETH USDT
     * @param in_code  借入币种标识，如：BTC ETH USDT
     * @param num      抵押数量
     * @param days     天数
     * @return
     */
    public void homeBorrowBorrowInfo(String type, String out_code, String in_code, String num, String days) {
        httpService.homeBorrowBorrowInfo(type, out_code, in_code, num, days).execute(new JsonCallBack<HttpData<HomeBorrowBorrowInfoBean>>() {
            @Override
            public void onSuccess(Response<HttpData<HomeBorrowBorrowInfoBean>> response) {
                HttpData<HomeBorrowBorrowInfoBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.updateRate(httpData.getData());
                }
            }
        });
    }

    /**
     * 获取抵押币信息
     *
     * @param out_code 抵押币种标识，如：BTC ETH USDT
     * @return
     */
    public void homeBorrowMortgageInfo(String type, String out_code) {
        httpService.homeBorrowMortgageInfo(type, out_code).execute(new JsonCallBack<HttpData<HomeBorrowMortgageInfoBean>>(this) {
            @Override
            public void onSuccess(Response<HttpData<HomeBorrowMortgageInfoBean>> response) {
                HttpData<HomeBorrowMortgageInfoBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.changeMortgageCoin(httpData.getData());
                }
            }
        });
    }

    /**
     * 抵押借款
     *
     * @param type     1押币借钱 2押钱借币
     * @param out_code 抵押币种标识，如：BTC ETH USDT
     * @param in_code  借入币种标识，如：BTC ETH USDT
     * @param num      抵押数量
     * @param days     天数
     * @param in_num   借款数量
     * @return
     */
    public void homeBorrowBorrowAdd(String type, String out_code, String in_code, String num, String days, String in_num, String tpwd) {
        httpService.homeBorrowBorrowAdd(type, out_code, in_code, num, days, in_num, tpwd).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.borrowSuccess();
                }
            }
        });
    }

    /**
     * 可抵押币种列表
     *
     * @param type type=1 借钱 type=2借币
     * @return
     */
    public void homeQbwCoinsListUp(String type) {
        httpService.homeQbwCoinsList(type).execute(new JsonCallBack<HttpData<List<HomeQbwCoinsList>>>(this) {
            @Override
            public void onSuccess(Response<HttpData<List<HomeQbwCoinsList>>> response) {
                HttpData<List<HomeQbwCoinsList>> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.updateMortgageCoin(httpData.getData());
                }
            }
        });
    }

    /**
     * 可抵押币种列表
     *
     * @param type type=1 借钱 type=2借币
     * @return
     */
    public void homeQbwCoinsListDown(String type) {
        httpService.homeQbwCoinsList(type).execute(new JsonCallBack<HttpData<List<HomeQbwCoinsList>>>(this) {
            @Override
            public void onSuccess(Response<HttpData<List<HomeQbwCoinsList>>> response) {
                HttpData<List<HomeQbwCoinsList>> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.updateBorrowCoin(httpData.getData());
                }
            }
        });
    }

    public void getMorgageDay() {
        httpService.getMorgageDay()
                .execute(new JsonCallBack<HttpData<List<String>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<String>>> response) {
                        HttpData<List<String>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateMorgageDay(httpData.getData());
                        }
                    }
                });
    }
}
